home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Source.bin / BorderPanel.java < prev    next >
Text File  |  1998-09-23  |  49KB  |  1,612 lines

  1. package symantec.itools.awt;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import java.beans.PropertyVetoException;
  6. import java.beans.PropertyChangeListener;
  7. import java.beans.VetoableChangeListener;
  8. import java.beans.PropertyChangeEvent;
  9. import symantec.itools.awt.util.ColorUtils;
  10. import java.awt.event.ContainerListener;
  11. import java.awt.event.ContainerEvent;
  12. import java.util.Vector;
  13. import java.util.ResourceBundle;
  14.  
  15. import java.lang.IllegalArgumentException;
  16.  
  17. //    01/29/97    TWB    Integrated changes from Macintosh
  18. //  05/31/97    RKM    Updated to support Java 1.1
  19. //                    Made properties bound & constrained
  20. //  07/19/97    LAB    Reorganized code to follow the GoodBeanSpec.  Updated deprecated
  21. //                    preferredSize and minimumSize calls. Made default protection
  22. //                    methods protected. Updated version to 1.1.
  23. //  07/20/97    RKM    Changed to new addImpl override, removed the five add variant overrides
  24. //  07/23/97    LAB    Constrained the BevelStyle property to only known styles.  Changed
  25. //                    setBorderColor(Color clr, boolean useForLabel) to throw a PropertyVetoException
  26. //                    as it should.  Updated to calculate the bevel raised and bevel lowered colors
  27. //                    from the background color.  Updated calls to reshape to setBounds.  Deprecated
  28. //                    reshape in favor of setBounds.
  29. //  07/25/97    CAR marked fields transient as needed
  30. //                  innerclasses implement java.io.Serialize
  31. //                  added back in null layout check in setLayout, without this check the bean throws an NullPointer
  32. //                  exception at instantiation time
  33. //  08/04/97    LAB    Now uses ColorUtils.calculateHilightColor and ColorUtils.calculateShadowColor
  34. //                    to calculate the bevel colors more intelligently.
  35. //    08/15/97    LAB    Reworked the way colors were calculated to avoid NullPointerExceptions,
  36. //                    and potential redraw problems.  Now colors are recalculated in paint,
  37. //                    if needed.
  38. //  08/29/97    CAR modified getPreferredSize and getMinimumSize
  39. //  09/01/97    CAR calls to add/removeContainerListener use the inner panel (which is considered the main container)
  40. //                  container events must appear to be generated by the outermost panel
  41. //    09/11/97    LAB    Added repaint call to setPaddingLeft, Right, Top, and Bottom, and added
  42. //                    a fillRect to draw() to fix some drawing artifacts (Addresses Mac Bug #7617).
  43. //                    Changed names of strings in PropertyChangeEvent handling to follow Bean Spec
  44. //                    naming conventions.
  45. //  10/20/97    CAR moved error messages into ResourceBundle
  46.  
  47. /**
  48.  * BorderPanel is a panel component that has an optional border
  49.  * and optional text title.
  50.  * @version 1.1, July 19, 1997
  51.  * @author Symantec
  52.  */
  53. public class BorderPanel extends Panel implements AlignStyle, BevelStyle, ContainerListener
  54. {
  55.     /**
  56.      * Constructs a new default BorderPanel.
  57.      * Its label will be ALIGN_CENTERED and it will have a BEVEL_LINE style border.
  58.      */
  59.     public BorderPanel()
  60.     {
  61.         this(null, ALIGN_CENTERED, BEVEL_LINE);
  62.     }
  63.  
  64.     /**
  65.      * Constructs a new BorderPanel with the specified beveled border style.
  66.      * It will have the ALIGN_CENTERED label alignment style.
  67.      * @param style the desired beveled border style
  68.      * @see BevelStyle#BEVEL_RAISED
  69.      * @see BevelStyle#BEVEL_LOWERED
  70.      * @see BevelStyle#BEVEL_LINE
  71.      * @see BevelStyle#BEVEL_NONE
  72.      */
  73.     public BorderPanel(int style)
  74.     {
  75.         this(null, ALIGN_CENTERED, style);
  76.     }
  77.  
  78.     /**
  79.      * Constructs a new BorderPanel with the specified border label.
  80.      * Its label will be ALIGN_CENTERED and it will have a BEVEL_LINE style border.
  81.      * @param s the label for the panel's border
  82.      */
  83.     public BorderPanel(String s)
  84.     {
  85.         this(s, ALIGN_CENTERED, BEVEL_LINE);
  86.     }
  87.  
  88.     /**
  89.      * Constructs a new BorderPanel with the specified border label
  90.      * and given alignment.
  91.      * @param s the label for the panel's border
  92.      * @param alignment the label alignment
  93.      * @see AlignStyle#ALIGN_LEFT
  94.      * @see AlignStyle#ALIGN_CENTERED
  95.      * @see AlignStyle#ALIGN_RIGHT
  96.      */
  97.     public BorderPanel(String s, int alignment)
  98.     {
  99.         this(s, alignment, BEVEL_LINE);
  100.     }
  101.  
  102.     /**
  103.      * Constructs a new BorderPanel with the specified border label
  104.      * and given alignment and border styles.
  105.      * @param s the label for the panel's border
  106.      * @param alignment the label alignment
  107.      * @param style the border bevel style
  108.      * @see AlignStyle#ALIGN_LEFT
  109.      * @see AlignStyle#ALIGN_CENTERED
  110.      * @see AlignStyle#ALIGN_RIGHT
  111.      * @see BevelStyle#BEVEL_RAISED
  112.      * @see BevelStyle#BEVEL_LOWERED
  113.      * @see BevelStyle#BEVEL_LINE
  114.      * @see BevelStyle#BEVEL_NONE
  115.      */
  116.     public BorderPanel(String s, int alignment, int style)
  117.     {
  118.         borderColor    = Color.black;
  119.         labelColor  = Color.black;
  120.         padleft     = 6;
  121.         padright    = 6;
  122.         padtop      = 10;
  123.         padbottom   = 6;
  124.         ixPad       = 4;
  125.         iyPadTop    = 2;
  126.         iyPadBottom = 7;
  127.  
  128.         cachedBackground = getBackground();
  129.  
  130.         label = (s != null && s.length() == 0) ? null : s;
  131.         labelAlignment = alignment;
  132.         internalInsets = new Insets(10, 10, 10, 10);
  133.         this.style     = style;
  134.         super.setLayout(null);
  135.         super.add(panel = new Panel());
  136.         if (panel != null)
  137.             panel.setLayout(null);
  138.         sizepanel(true);
  139.         cListeners = new Vector();
  140.     }
  141.  
  142.     /**
  143.      * Sets the top border outside padding amount, in pixels.
  144.      * This is the distance between the drawn border and the actual
  145.      * bounds of the component.
  146.      * @param newPadTop the top border outside padding amount, in pixels
  147.      * @exception PropertyVetoException
  148.      * if the specified property value is unacceptable
  149.      * @see #getPaddingTop
  150.      */
  151.     public void setPaddingTop(int newPadTop) throws PropertyVetoException
  152.     {
  153.         if (padtop != newPadTop)
  154.         {
  155.             Integer oldPadTopInt = new Integer(padtop);
  156.             Integer newPadTopInt = new Integer(newPadTop);
  157.  
  158.             vetos.fireVetoableChange("paddingTop", oldPadTopInt, newPadTopInt);
  159.  
  160.             padtop = newPadTop;
  161.             sizepanel(true);
  162.             invalidate();
  163.                repaint();
  164.  
  165.             changes.firePropertyChange("paddingTop", oldPadTopInt, newPadTopInt);
  166.         }
  167.     }
  168.  
  169.     /**
  170.      * Gets the current top border outside padding amount, in pixels.
  171.      * This is the distance between the drawn border and the actual
  172.      * bounds of the component.
  173.      * @return the top border outside padding amount, in pixels
  174.      * @see #setPaddingTop
  175.      */
  176.     public int getPaddingTop()
  177.     {
  178.         return padtop;
  179.     }
  180.  
  181.     /**
  182.      * Sets the bottom border outside padding amount, in pixels.
  183.      * This is the distance between the drawn border and the actual
  184.      * bounds of the component.
  185.      * @param newPadBottom the bottom border outside padding amount, in pixels
  186.      * @exception PropertyVetoException
  187.      * if the specified property value is unacceptable
  188.      * @see #getPaddingBottom
  189.      */
  190.     public void setPaddingBottom(int newPadBottom) throws PropertyVetoException
  191.     {
  192.         if (padbottom != newPadBottom)
  193.         {
  194.             Integer oldPadBottomInt = new Integer(padbottom);
  195.             Integer newPadBottomInt = new Integer(newPadBottom);
  196.  
  197.             vetos.fireVetoableChange("paddingBottom", oldPadBottomInt, newPadBottomInt);
  198.  
  199.             padbottom = newPadBottom;
  200.             sizepanel(true);
  201.             invalidate();
  202.             repaint();
  203.  
  204.             changes.firePropertyChange("paddingBottom", oldPadBottomInt, newPadBottomInt);
  205.         }
  206.     }
  207.  
  208.     /**
  209.      * Gets the current bottom border outside padding amount, in pixels.
  210.      * This is the distance between the drawn border and the actual
  211.      * bounds of the component.
  212.      * @return the bottom border outside padding amount, in pixels
  213.      * @see #setPaddingBottom
  214.      */
  215.     public int getPaddingBottom()
  216.     {
  217.         return padbottom;
  218.     }
  219.  
  220.     /**
  221.      * Sets the left border outside padding amount, in pixels.
  222.      * This is the distance between the drawn border and the actual
  223.      * bounds of the component.
  224.      * @param newPadLeft the left border outside padding amount, in pixels
  225.      * @exception PropertyVetoException
  226.      * if the specified property value is unacceptable
  227.      * @see #getPaddingLeft
  228.      */
  229.     public void setPaddingLeft(int newPadLeft) throws PropertyVetoException
  230.     {
  231.         if (padleft != newPadLeft)
  232.         {
  233.             Integer oldPadLeftInt = new Integer(padleft);
  234.             Integer newPadLeftInt = new Integer(newPadLeft);
  235.  
  236.             vetos.fireVetoableChange("paddingLeft", oldPadLeftInt, newPadLeftInt);
  237.  
  238.             padleft = newPadLeft;
  239.             sizepanel(true);
  240.             invalidate();
  241.             repaint();
  242.  
  243.             changes.firePropertyChange("paddingLeft", oldPadLeftInt, newPadLeftInt);
  244.         }
  245.     }
  246.  
  247.     /**
  248.      * Gets the current left border outside padding amount, in pixels.
  249.      * This is the distance between the drawn border and the actual
  250.      * bounds of the component.
  251.      * @return the left border outside padding amount, in pixels
  252.      * @see #setPaddingLeft
  253.      */
  254.     public int getPaddingLeft()
  255.     {
  256.         return padleft;
  257.     }
  258.  
  259.     /**
  260.      * Sets the right border outside padding amount, in pixels.
  261.      * This is the distance between the drawn border and the actual
  262.      * bounds of the component.
  263.      * @param newPadRight the right border outside padding amount, in pixels
  264.      * @exception PropertyVetoException
  265.      * if the specified property value is unacceptable
  266.      * @see #getPaddingRight
  267.      */
  268.     public void setPaddingRight(int newPadRight) throws PropertyVetoException
  269.     {
  270.         if (padright != newPadRight)
  271.         {
  272.             Integer oldPadRightInt = new Integer(padright);
  273.             Integer newPadRightInt = new Integer(newPadRight);
  274.  
  275.             vetos.fireVetoableChange("paddingRight", oldPadRightInt, newPadRightInt);
  276.  
  277.             padright = newPadRight;
  278.             sizepanel(true);
  279.             invalidate();
  280.             repaint();
  281.  
  282.             changes.firePropertyChange("paddingRight", oldPadRightInt, newPadRightInt);
  283.         }
  284.     }
  285.  
  286.     /**
  287.      * Gets the current right border outside padding amount, in pixels.
  288.      * This is the distance between the drawn border and the actual
  289.      * bounds of the component.
  290.      * @return the right border outside padding amount, in pixels
  291.      * @see #setPaddingRight
  292.      */
  293.     public int getPaddingRight()
  294.     {
  295.         return padright;
  296.     }
  297.  
  298.     /**
  299.      * Sets the top border inset padding amount, in pixels.
  300.      * This is the distance between the drawn border and the usable
  301.      * area within the border. It is used to determine the size of the
  302.      * panel contained within this component's borders.
  303.      * @param t top border inset padding amount
  304.      * @exception PropertyVetoException
  305.      * if the specified property value is unacceptable
  306.      * @see #getIPadTop
  307.      * @see #panel
  308.      */
  309.     public void setIPadTop(int t) throws PropertyVetoException
  310.     {
  311.         if (iyPadTop != t)
  312.         {
  313.             Integer oldPadTopInt = new Integer(iyPadTop);
  314.             Integer newPadTopInt = new Integer(t);
  315.  
  316.             vetos.fireVetoableChange("iPadTop", oldPadTopInt, newPadTopInt);
  317.  
  318.             iyPadTop = t;
  319.  
  320.             changes.firePropertyChange("iPadTop", oldPadTopInt, newPadTopInt);
  321.  
  322.             sizepanel(true);
  323.             invalidate();
  324.         }
  325.     }
  326.  
  327.     /**
  328.      * Gets the current top border inset padding amount, in pixels.
  329.      * This is the distance between the drawn border and the usable
  330.      * area within the border. It is used to determine the size of the
  331.      * panel contained within this component's borders.
  332.      * @return top border inset padding amount
  333.      * @see #setIPadTop
  334.      * @see #panel
  335.      */
  336.     public int getIPadTop()
  337.     {
  338.         return iyPadTop;
  339.     }
  340.  
  341.     /**
  342.      * Sets the bottom border inset padding amount, in pixels.
  343.      * This is the distance between the drawn border and the usable
  344.      * area within the border. It is used to determine the size of the
  345.      * panel contained within this component's borders.
  346.      * @param b bottom border inset padding amount
  347.      * @exception PropertyVetoException
  348.      * if the specified property value is unacceptable
  349.      * @see #getIPadBottom
  350.      * @see #panel
  351.      */
  352.     public void setIPadBottom(int b) throws PropertyVetoException
  353.     {
  354.         if (iyPadBottom != b)
  355.         {
  356.             Integer oldPadBottomInt = new Integer(iyPadBottom);
  357.             Integer newPadBottomInt = new Integer(b);
  358.  
  359.             vetos.fireVetoableChange("iPadBottom", oldPadBottomInt, newPadBottomInt);
  360.  
  361.             iyPadBottom = b;
  362.  
  363.             changes.firePropertyChange("iPadBottom", oldPadBottomInt, newPadBottomInt);
  364.  
  365.             sizepanel(true);
  366.             invalidate();
  367.         }
  368.     }
  369.  
  370.     /**
  371.      * Gets the current bottom border inset padding amount, in pixels.
  372.      * This is the distance between the drawn border and the usable
  373.      * area within the border. It is used to determine the size of the
  374.      * panel contained within this component's borders.
  375.      * @return bottom border inset padding amount
  376.      * @see #setIPadBottom
  377.      * @see #panel
  378.      */
  379.     public int getIPadBottom()
  380.     {
  381.         return iyPadBottom;
  382.     }
  383.  
  384.     /**
  385.      * Sets the side border inset padding amount, in pixels.
  386.      * This is the distance between the drawn border and the usable
  387.      * area within the border. It is used to determine the size of the
  388.      * panel contained within this component's borders.
  389.      * @param s side border inset padding amount
  390.      * @exception PropertyVetoException
  391.      * if the specified property value is unacceptable
  392.      * @see #getIPadSides
  393.      * @see #panel
  394.      */
  395.     public void setIPadSides(int s) throws PropertyVetoException
  396.     {
  397.         if (ixPad != s)
  398.         {
  399.             Integer oldIPadSidesInt = new Integer(ixPad);
  400.             Integer newIPadSidesInt = new Integer(s);
  401.  
  402.             vetos.fireVetoableChange("iPadSides", oldIPadSidesInt, newIPadSidesInt);
  403.  
  404.             ixPad = s;
  405.  
  406.             changes.firePropertyChange("iPadSides", oldIPadSidesInt, newIPadSidesInt);
  407.  
  408.             sizepanel(true);
  409.             invalidate();
  410.         }
  411.     }
  412.  
  413.     /**
  414.      * Gets the current side border inset padding amount, in pixels.
  415.      * This is the distance between the drawn border and the usable
  416.      * area within the border. It is used to determine the size of the
  417.      * panel contained within this component's borders.
  418.      * @return side border inset padding amount
  419.      * @see #setIPadSides
  420.      * @see #panel
  421.      */
  422.     public int getIPadSides()
  423.     {
  424.         return ixPad;
  425.     }
  426.  
  427.     /**
  428.      * Sets the text label to display in the border.
  429.      * @param newLabel the new border label.  If null, label is removed
  430.      * @exception PropertyVetoException
  431.      * if the specified property value is unacceptable
  432.      * @see #getLabel
  433.      */
  434.     public void setLabel(String newLabel) throws PropertyVetoException
  435.     {
  436.         //Preprocess s, since null is what instead of an empty string
  437.         if (newLabel != null && newLabel.length() == 0)
  438.             newLabel = null;
  439.  
  440.         if (!symantec.itools.util.GeneralUtils.objectsEqual(label,newLabel))
  441.         {
  442.             String oldLabel = label;
  443.  
  444.             vetos.fireVetoableChange("label", oldLabel, newLabel);
  445.  
  446.             label = newLabel;
  447.  
  448.             changes.firePropertyChange("label", oldLabel, newLabel);
  449.  
  450.             sizepanel(true);
  451.             //invalidate();
  452.             repaint();
  453.         }
  454.     }
  455.  
  456.     /**
  457.      * Returns the text label displayed in the border.
  458.      * @see #setLabel
  459.      */
  460.     public String getLabel()
  461.     {
  462.         return label;
  463.     }
  464.  
  465.     /**
  466.      * Sets the current border color.
  467.      * @param newBorderColor the new border color
  468.      * @exception PropertyVetoException
  469.      * if the specified property value is unacceptable
  470.      * @see #getBorderColor
  471.      */
  472.     public void setBorderColor(Color newBorderColor) throws PropertyVetoException
  473.     {
  474.         if (!symantec.itools.util.GeneralUtils.objectsEqual(borderColor,newBorderColor))
  475.         {
  476.             Color oldBorderColor = borderColor;
  477.  
  478.             vetos.fireVetoableChange("borderColor",oldBorderColor,newBorderColor);
  479.  
  480.             borderColor            = newBorderColor;
  481.  
  482.             changes.firePropertyChange("borderColor",oldBorderColor,newBorderColor);
  483.  
  484.             repaint();
  485.         }
  486.     }
  487.  
  488.     /**
  489.      * Gets the current border color.
  490.      * @return the current border color
  491.      * @see #setBorderColor
  492.      */
  493.     public Color getBorderColor()
  494.     {
  495.         return borderColor;
  496.     }
  497.  
  498.     /**
  499.      * Sets the border label color.
  500.      * @param newLabelBorderColor new border label color
  501.      * @exception PropertyVetoException
  502.      * if the specified property value is unacceptable
  503.      * @see #getLabelColor
  504.      */
  505.     public void setLabelColor(Color newLabelBorderColor) throws PropertyVetoException
  506.     {
  507.         if (!symantec.itools.util.GeneralUtils.objectsEqual(labelColor,newLabelBorderColor))
  508.         {
  509.             Color oldLabelColor = labelColor;
  510.  
  511.             vetos.fireVetoableChange("labelColor",oldLabelColor,newLabelBorderColor);
  512.  
  513.             labelColor = newLabelBorderColor;
  514.  
  515.             changes.firePropertyChange("labelColor",oldLabelColor,newLabelBorderColor);
  516.  
  517.             repaint();
  518.         }
  519.     }
  520.  
  521.     /**
  522.      * Gets the current border label color.
  523.      * @return current border label color
  524.      */
  525.     public Color getLabelColor()
  526.     {
  527.         return labelColor;
  528.     }
  529.  
  530.     /**
  531.      * Sets the border label alignment.
  532.      * @param alignment the new border label alignment.
  533.      * One of ALIGN_LEFT, ALIGN_CENTERED, or ALIGN_RIGHT
  534.      * @exception PropertyVetoException
  535.      * if the specified property value is unacceptable
  536.      * @see #getAlignStyle
  537.      * @see AlignStyle#ALIGN_LEFT
  538.      * @see AlignStyle#ALIGN_CENTERED
  539.      * @see AlignStyle#ALIGN_RIGHT
  540.      */
  541.     public void setAlignStyle(int newLabelAlignment) throws PropertyVetoException
  542.     {
  543.         if (labelAlignment != newLabelAlignment)
  544.         {
  545.             Integer oldLabelAlignmentInteger = new Integer(labelAlignment);
  546.             Integer newLabelAlignmentInteger = new Integer(newLabelAlignment);
  547.  
  548.             vetos.fireVetoableChange("alignStyle",oldLabelAlignmentInteger,newLabelAlignmentInteger);
  549.  
  550.             labelAlignment = newLabelAlignment;
  551.  
  552.             changes.firePropertyChange("alignStyle",oldLabelAlignmentInteger,newLabelAlignmentInteger);
  553.  
  554.             sizepanel(true);
  555.             //invalidate();
  556.             repaint();
  557.         }
  558.     }
  559.  
  560.     /**
  561.      * Gets the current border label alignment.
  562.      * @return the current border label alignment.
  563.      * One of ALIGN_LEFT, ALIGN_CENTERED, or ALIGN_RIGHT
  564.      * @see AlignStyle#ALIGN_LEFT
  565.      * @see AlignStyle#ALIGN_CENTERED
  566.      * @see AlignStyle#ALIGN_RIGHT
  567.      * @see #setAlignStyle
  568.      */
  569.     public int getAlignStyle()
  570.     {
  571.         return labelAlignment;
  572.     }
  573.  
  574.     /**
  575.      * Sets the border style.
  576.      * @param s the new border style.
  577.      * One of BEVEL_RAISED, BEVEL_LOWERED, BEVEL_LINE, or BEVEL_NONE
  578.      * @exception PropertyVetoException
  579.      * if the specified property value is unacceptable
  580.      * @see BevelStyle#BEVEL_RAISED
  581.      * @see BevelStyle#BEVEL_LOWERED
  582.      * @see BevelStyle#BEVEL_LINE
  583.      * @see BevelStyle#BEVEL_NONE
  584.      * @see #getBevelStyle
  585.      */
  586.     public void setBevelStyle(int newBevelStyle) throws PropertyVetoException
  587.     {
  588.         if (style != newBevelStyle)
  589.         {
  590.             Integer oldBevelStyleInteger = new Integer(style);
  591.             Integer newBevelStyleInteger = new Integer(newBevelStyle);
  592.  
  593.             vetos.fireVetoableChange("bevelStyle",oldBevelStyleInteger,newBevelStyleInteger);
  594.  
  595.             style = newBevelStyle;
  596.  
  597.             changes.firePropertyChange("bevelStyle",oldBevelStyleInteger,newBevelStyleInteger);
  598.  
  599.             repaint();
  600.         }
  601.     }
  602.  
  603.     /**
  604.      * Gets the current border style.
  605.      * @return current border style.
  606.      * One of BEVEL_RAISED, BEVEL_LOWERED, BEVEL_LINE, or BEVEL_NONE
  607.      * @see BevelStyle#BEVEL_RAISED
  608.      * @see BevelStyle#BEVEL_LOWERED
  609.      * @see BevelStyle#BEVEL_LINE
  610.      * @see BevelStyle#BEVEL_NONE
  611.      * @see #setBevelStyle
  612.      */
  613.     public int getBevelStyle()
  614.     {
  615.         return style;
  616.     }
  617.  
  618.     //???RKM??? Need JavaDoc here BUG: Was dup of getInternalInsets
  619.     /**
  620.      * Sets the internal border insets.
  621.      * The left and right fields of the internal insets are used while
  622.      * determining the preferred width of this component.
  623.      * @param newInsets the new internal border insets
  624.      * @exception PropertyVetoException
  625.      * if the specified property value is unacceptable
  626.      * @see #getInternalInsets
  627.      */
  628.     public void setInternalInsets(Insets newInsets) throws PropertyVetoException
  629.     {
  630.         if (!symantec.itools.util.GeneralUtils.objectsEqual(internalInsets,newInsets))
  631.         {
  632.             Insets oldInsets = internalInsets;
  633.  
  634.             vetos.fireVetoableChange("internalInsets",oldInsets,newInsets);
  635.  
  636.             internalInsets = newInsets;
  637.  
  638.             changes.firePropertyChange("internalInsets",oldInsets,newInsets);
  639.  
  640.             sizepanel(true);
  641.             invalidate();
  642.         }
  643.     }
  644.  
  645.     /**
  646.      * Gets the current internal border insets.
  647.      * The left and right fields of the internal insets are used while
  648.      * determining the preferred width of this component.
  649.      * @return the current internal border insets
  650.      * @see #setInternalInsets
  651.      */
  652.     public Insets getInternalInsets()
  653.     {
  654.         return internalInsets;
  655.     }
  656.  
  657.     /**
  658.      * Sets the border padding amounts.
  659.      * This are the distances between the drawn border and the actual
  660.      * bounds of the component.
  661.      * @param t the top padding amount
  662.      * @param b the bottom padding amount
  663.      * @param l the left padding amount
  664.      * @param r the right padding amount
  665.      * @exception PropertyVetoException
  666.      * if the specified property value is unacceptable
  667.      */
  668.     public void setPadding(int t, int b, int l, int r) throws PropertyVetoException
  669.     {
  670.         setPaddingTop(t);
  671.         setPaddingBottom(b);
  672.         setPaddingLeft(l);
  673.         setPaddingRight(r);
  674.     }
  675.  
  676.     /**
  677.      * @deprecated As of JDK version 1.1,
  678.      * replaced by setBorderColor & setLabelColor.
  679.      * @exception PropertyVetoException
  680.      * if the specified property value is unacceptable
  681.      * @see #setBorderColor(java.awt.Color)
  682.      * @see #setLabelColor(java.awt.Color)
  683.      */
  684.     public void setBorderColor(Color clr, boolean useForLabel) throws PropertyVetoException
  685.     {
  686.         setBorderColor(clr);
  687.  
  688.         if (useForLabel)
  689.         {
  690.             setLabelColor(clr);
  691.         }
  692.     }
  693.  
  694.     /**
  695.      * Returns the recommended dimensions to properly display this component.
  696.      * This is a standard Java AWT method which gets called to determine
  697.      * the recommended size of this component. The size returned is large
  698.      * enough to display the entire border label and the panel within the
  699.      * border.
  700.      *
  701.      * @see #minimumSize
  702.      */
  703.     public Dimension getPreferredSize()
  704.     {
  705.         Dimension p = size();
  706.         Dimension m = getMinimumSize();
  707.         return new Dimension(Math.max(p.width, m.width), Math.max(p.height, m.height));
  708.     }
  709.  
  710.     /**
  711.      * @deprecated
  712.      * @see #getPreferredSize
  713.      */
  714.     public Dimension preferredSize()
  715.     {
  716.         return getPreferredSize();
  717.     }
  718.  
  719.     /**
  720.      * Returns the minimum dimensions to properly display this component.
  721.      * This is a standard Java AWT method which gets called to determine
  722.      * the minimum size of this component.
  723.      *
  724.      * @see #getPreferredSize
  725.      */
  726.     public Dimension getMinimumSize()
  727.     {
  728.         return new Dimension(20, 40);
  729.     }
  730.  
  731.     /**
  732.      * @deprecated
  733.      * @see #getMinimumSize
  734.      */
  735.     public Dimension minimumSize()
  736.     {
  737.         return getMinimumSize();
  738.     }
  739.  
  740.     /**
  741.      * Sets the layout manager to be used to layout this container.
  742.      * This is a standard Java AWT method which gets called to specify
  743.      * which layout manager should be used to layout the components in
  744.      * standard containers.
  745.      *
  746.      * @param l the layout manager to use to layout this container's components
  747.      * @see #getLayout
  748.      **/
  749.     public void setLayout(LayoutManager l)
  750.     {
  751.         if (panel != null)
  752.         {
  753.             panel.setLayout(l);
  754.         }
  755.     }
  756.  
  757.     /**
  758.      * Gets the current border panel layout manager.
  759.      * @return current LayoutManager of border panel
  760.      * @see #setLayout
  761.      */
  762.     public LayoutManager getLayout()
  763.     {
  764.         return panel.getLayout();
  765.     }
  766.  
  767.     /**
  768.      * Gets the component at the specified zero-relative component index.
  769.      * This is a standard Java AWT method which gets called to return
  770.      * the component at a specific position.
  771.      *
  772.      * @param i the zero-relative index of the component to retrieve
  773.      * @return the component at the given index
  774.      * @exception java.lang.ArrayIndexOutOfBoundsException if the given
  775.      * component index does not exist
  776.      * @see #getComponents
  777.      */
  778.     public Component getComponent(int i)
  779.     {
  780.         return panel.getComponent(i);
  781.     }
  782.  
  783.     /**
  784.      * Returns all of the components in this container.
  785.      * This is a standard Java AWT method which gets called to return
  786.      * an array of all of the components in this container.
  787.      *
  788.      * @return an array of components in this container
  789.      * @see #getComponent
  790.      */
  791.     public Component[] getComponents()
  792.     {
  793.         return panel.getComponents();
  794.     }
  795.  
  796.     /**
  797.      * Returns the number of components in this container.
  798.      *
  799.      * @return the number of components in this container
  800.      * @see #getComponent
  801.      */
  802.     public int getComponentCount()
  803.     {
  804.         return panel.getComponentCount();
  805.     }
  806.  
  807.     /**
  808.      * Is the specified bevelStyle valid?
  809.      * @param bevelStyle the style to test
  810.      * @return if true then the parameter was equal to one of the following:
  811.      * @see BevelStyle#BEVEL_RAISED
  812.      * @see BevelStyle#BEVEL_LOWERED
  813.      * @see BevelStyle#BEVEL_LINE
  814.      * @see BevelStyle#BEVEL_NONE
  815.      */
  816.     public boolean isValidBevelStyle(int bevelStyle)
  817.     {
  818.         switch(bevelStyle)
  819.         {
  820.             case BEVEL_RAISED:
  821.             case BEVEL_LOWERED:
  822.             case BEVEL_LINE:
  823.             case BEVEL_NONE:
  824.                 return true;
  825.             default:
  826.                 return false;
  827.         }
  828.     }
  829.  
  830.     /**
  831.      * Tells this component that it has been added to a container.
  832.      * This is a standard Java AWT method which gets called by the AWT when
  833.      * this component is added to a container. Typically, it is used to
  834.      * create this component's peer.
  835.      *
  836.      * It has been overridden here to hook-up event listeners, and
  837.      * to resize self after peer created.
  838.      *
  839.      * @see #removeNotify
  840.      */
  841.     public synchronized void addNotify()
  842.     {
  843.         super.addNotify();
  844.         errors = ResourceBundle.getBundle("symantec.itools.resources.ErrorsBundle");
  845.  
  846.         sizepanel(true);
  847.  
  848.         //Hook up listeners
  849.         if (veto == null)
  850.         {
  851.             veto = new Veto();
  852.             addBevelStyleListener(veto);
  853.         }
  854.  
  855.         if (panel != null)
  856.             panel.addContainerListener(this);
  857.     }
  858.  
  859.     /**
  860.      * Tells this component that it is being removed from a container.
  861.      * This is a standard Java AWT method which gets called by the AWT when
  862.      * this component is removed from a container. Typically, it is used to
  863.      * destroy the peers of this component and all its subcomponents.
  864.      *
  865.      * It has been overridden here to unhook event listeners.
  866.      *
  867.      * @see #addNotify
  868.      */
  869.     public synchronized void removeNotify()
  870.     {
  871.         //Unhook listeners
  872.         if (veto != null)
  873.         {
  874.             removeBevelStyleListener(veto);
  875.             veto = null;
  876.         }
  877.  
  878.         if (panel != null)
  879.             panel.removeContainerListener(this);
  880.  
  881.         super.removeNotify();
  882.     }
  883.  
  884.     /**
  885.      * Handles the laying out of components within this component.
  886.      * This is a standard Java AWT method which gets called by the AWT
  887.      * when this component is validated with the validate() method.
  888.      *
  889.      * @see java.awt.Container#validate
  890.      */
  891.     public void layout()
  892.     {
  893.         sizepanel(false);
  894.         panel.layout();
  895.     }
  896.  
  897.     /**
  898.      * Adds the specified component to this container at the specified
  899.      * index.  Also notifies the layout manager to add the component to
  900.      * the this container's layout using the specified constraints object.
  901.      * <p>
  902.      * This is the method to override if you want to track every add
  903.      * request to a container.  An overriding method should usually
  904.      * include a call to super.addImpl(comp, constraints, index).
  905.      *
  906.      * BorderPanel overrides this method to send all additions to it to\
  907.      * its internal panel
  908.      *
  909.      * @param comp the component to be added
  910.      * @param constraints an object expressing layout contraints for this
  911.      * component
  912.      * @param index the position in the container's list at which to
  913.      * insert the component.  -1 means insert at the end.
  914.      * @see #remove
  915.      * @see LayoutManager
  916.      */
  917.     protected void addImpl(Component comp, Object constraints, int index)
  918.     {
  919.         if (comp == panel)
  920.             super.addImpl(comp,constraints,index);
  921.         else
  922.             panel.add(comp,constraints,index);
  923.     }
  924.  
  925.     /**
  926.      * Removes the component at the specified index from this container.
  927.      * @param index the index of the component to be removed
  928.      * @see java.awt.Container#add
  929.      */
  930.     public void remove(int index)
  931.     {
  932.         panel.remove(index);
  933.     }
  934.  
  935.     public void remove(Component comp)
  936.     {
  937.         panel.remove(comp);
  938.     }
  939.  
  940.     /**
  941.      * Removes all the components from this container.
  942.      * This is a standard Java AWT method which gets called to remove all
  943.      * the components from a container. When this happens each component's
  944.      * removeNotify() will also get called to indicate component removal.
  945.      *
  946.      * @see #remove
  947.      * @see java.awt.Container#add
  948.      */
  949.     public void removeAll()
  950.     {
  951.         panel.removeAll();
  952.     }
  953.  
  954.     /**
  955.      * Moves and/or resizes this component.
  956.      * This is a standard Java AWT method which gets called to move and/or
  957.      * resize this component. Components that are in containers with layout
  958.      * managers should not call this method, but rely on the layout manager
  959.      * instead.
  960.      *
  961.      * @param x horizontal position in the parent's coordinate space
  962.      * @param y vertical position in the parent's coordinate space
  963.      * @param width the new width
  964.      * @param height the new height
  965.      */
  966.     public void setBounds(int x, int y, int width, int height)
  967.     {
  968.         super.setBounds(x, y, width, height);
  969.         sizepanel(false);
  970.     }
  971.  
  972.     /**
  973.      * @deprecated
  974.      * @see #setBounds
  975.      */
  976.     public void reshape(int x, int y, int width, int height)
  977.     {
  978.         //Can not call setBounds here, or we would be in an endless loop because of the AWT.
  979.         super.reshape(x, y, width, height);
  980.         sizepanel(false);
  981.     }
  982.  
  983.     /**
  984.      * Handles redrawing of this component on the screen.
  985.      * This is a standard Java AWT method which gets called by the Java
  986.      * AWT (repaint()) to handle repainting this component on the screen.
  987.      * The graphics context clipping region is set to the bounding rectangle
  988.      * of this component and its [0,0] coordinate is this component's
  989.      * top-left corner.
  990.      * Typically this method paints the background color to clear the
  991.      * component's drawing space, sets graphics context to be the foreground
  992.      * color, and then calls paint() to draw the component.
  993.      *
  994.      * @param g the graphics context
  995.      * @see java.awt.Component#repaint
  996.      * @see #paint
  997.      */
  998.     public void update(Graphics g)
  999.     {
  1000.         Dimension s;
  1001.         Insets insets;
  1002.  
  1003.         s      = size();
  1004.         insets = insets();
  1005.  
  1006.         //??? LAB ??? What is all this doing?  Doesn't seem to apply.
  1007.         g.setColor(getBackground());
  1008.  
  1009.         if (insets.left > 0)
  1010.         {
  1011.             g.fillRect(0, 0, insets.left, s.height);
  1012.         }
  1013.  
  1014.         if (insets.top > 0)
  1015.         {
  1016.             g.fillRect(0, 0, s.width, insets.top);
  1017.         }
  1018.  
  1019.         if (insets.bottom > 0)
  1020.         {
  1021.             g.fillRect(0, s.height-insets.bottom, s.width, insets.bottom);
  1022.         }
  1023.  
  1024.         if (insets.right > 0)
  1025.         {
  1026.             g.fillRect(s.width-insets.right, 0, insets.right, s.height);
  1027.         }
  1028.  
  1029.         paint(g);
  1030.         panel.repaint();
  1031.     }
  1032.  
  1033.     /**
  1034.      * Returns the number of components in this container.
  1035.      * This is a standard Java AWT method which gets called to return a count
  1036.      * of the components within this container.
  1037.      *
  1038.      */
  1039.     public int countComponents()
  1040.     {
  1041.         return panel.countComponents();
  1042.     }
  1043.  
  1044.     /**
  1045.      * Returns the amount of space used by the current border.
  1046.      * This is a standard Java AWT method which gets called to determine
  1047.      * the size of the current border. The returned value is the width
  1048.      * of each border side in pixels.
  1049.      *
  1050.      * @return the current border insets
  1051.      */
  1052.     public Insets insets()
  1053.     {
  1054.         int h = getLabelTopMargin();
  1055.         Insets insets = getInternalInsets();
  1056.  
  1057.         return new Insets(h + insets.top, insets.left, insets.bottom, insets.right);
  1058.     }
  1059.  
  1060.     /**
  1061.      * Paints this component using the given graphics context.
  1062.      * This is a standard Java AWT method which typically gets called
  1063.      * by the AWT to handle painting this component. It paints this component
  1064.      * using the given graphics context. The graphics context clipping region
  1065.      * is set to the bounding rectangle of this component and its [0,0]
  1066.      * coordinate is this component's top-left corner.
  1067.      *
  1068.      * @param g the graphics context used for painting
  1069.      * @see java.awt.Component#repaint
  1070.      * @see #update
  1071.      */
  1072.     public void paint(Graphics g)
  1073.     {
  1074.         sizepanel(false);
  1075.         Color curBackground = getBackground();
  1076.         if (!symantec.itools.util.GeneralUtils.objectsEqual(curBackground, cachedBackground))
  1077.         {
  1078.             cachedBackground = curBackground;
  1079.             calculateHilightColors(curBackground);
  1080.         }
  1081.         g.setColor(curBackground);
  1082.         draw(g);
  1083.     }
  1084.  
  1085.     /**
  1086.      * Sets this component's background color.
  1087.      * This is a standard Java AWT method which gets called to change
  1088.      * the background color of this component.
  1089.      *
  1090.      * @param c the new background color
  1091.      * @see java.awt.Component#getBackground
  1092.      */
  1093.     public void setBackground(Color c)
  1094.     {
  1095.         super.setBackground(c);
  1096.         panel.setBackground(c);
  1097.     }
  1098.  
  1099.     /**
  1100.      * A method of the ContainerListener interface.
  1101.      * This method is called when a component is added to this component's panel.
  1102.      * @param e the container event
  1103.      * @see java.awt.ContainerListener
  1104.      */
  1105.     public void componentAdded(ContainerEvent e) {
  1106.         if (e.getSource() == panel) {
  1107.             for (int i = 0; i < cListeners.size(); ++i) {
  1108.                 ((ContainerListener) cListeners.elementAt(i)).componentAdded(
  1109.                     new ContainerEvent(this, ContainerEvent.COMPONENT_ADDED, e.getChild()));
  1110.             }
  1111.         }
  1112.     }
  1113.  
  1114.     /**
  1115.      * A method of the ContainerListener interface.
  1116.      * This method is called when a component is removed from this component's panel.
  1117.      * @param e the container event
  1118.      * @see java.awt.ContainerListener
  1119.      */
  1120.     public void componentRemoved(ContainerEvent e) {
  1121.         if (e.getSource() == panel) {
  1122.             for (int i = 0; i < cListeners.size(); ++i) {
  1123.                 ((ContainerListener) cListeners.elementAt(i)).componentRemoved(
  1124.                     new ContainerEvent(this, ContainerEvent.COMPONENT_REMOVED, e.getChild()));
  1125.             }
  1126.         }
  1127.     }
  1128.  
  1129.     public synchronized void addContainerListener(ContainerListener l) {
  1130.         if (panel != null) {
  1131.             panel.addContainerListener(l);
  1132.             cListeners.addElement(l);
  1133.         }
  1134.     }
  1135.  
  1136.     public synchronized void removeContainerListener(ContainerListener l) {
  1137.         if (panel != null) {
  1138.             panel.removeContainerListener(l);
  1139.             cListeners.removeElement(l);
  1140.         }
  1141.     }
  1142.  
  1143.     /**
  1144.      * Adds a listener for all event changes.
  1145.      * @param listener the listener to add.
  1146.      * @see #removePropertyChangeListener
  1147.      */
  1148.     public synchronized void addPropertyChangeListener(PropertyChangeListener listener)
  1149.     {
  1150.         //super.addPropertyChangeListener(listener);
  1151.         changes.addPropertyChangeListener(listener);
  1152.     }
  1153.  
  1154.     /**
  1155.      * Removes a listener for all event changes.
  1156.      * @param listener the listener to remove.
  1157.      * @see #addPropertyChangeListener
  1158.      */
  1159.     public synchronized void removePropertyChangeListener(PropertyChangeListener listener)
  1160.     {
  1161.         //super.removePropertyChangeListener(listener);
  1162.         changes.removePropertyChangeListener(listener);
  1163.     }
  1164.  
  1165.     /**
  1166.      * Adds a vetoable listener for all event changes.
  1167.      * @param listener the listener to add.
  1168.      * @see #removeVetoableChangeListener
  1169.      */
  1170.     public synchronized void addVetoableChangeListener(VetoableChangeListener listener)
  1171.     {
  1172.          //super.addVetoableChangeListener(listener);
  1173.         vetos.addVetoableChangeListener(listener);
  1174.     }
  1175.  
  1176.     /**
  1177.      * Removes a vetoable listener for all event changes.
  1178.      * @param listener the listener to remove.
  1179.      * @see #addVetoableChangeListener
  1180.      */
  1181.     public synchronized void removeVetoableChangeListener(VetoableChangeListener listener)
  1182.     {
  1183.         //super.removeVetoableChangeListener(listener);
  1184.         vetos.removeVetoableChangeListener(listener);
  1185.     }
  1186.  
  1187.     /**
  1188.      * Adds a listener for Orienation changes.
  1189.      * @param listener the listener to add.
  1190.      * @see #removeBevelStyleListener
  1191.      */
  1192.     public synchronized void addBevelStyleListener(PropertyChangeListener listener)
  1193.     {
  1194.         changes.addPropertyChangeListener("bevelStyle", listener);
  1195.     }
  1196.  
  1197.     /**
  1198.      * Removes a listener for Orienation changes.
  1199.      * @param listener the listener to remove.
  1200.      * @see #addBevelStyleListener
  1201.      */
  1202.     public synchronized void removeBevelStyleListener(PropertyChangeListener listener)
  1203.     {
  1204.         changes.removePropertyChangeListener("bevelStyle", listener);
  1205.     }
  1206.  
  1207.     /**
  1208.      * Adds a vetoable listener for BevelStyle changes.
  1209.      * @param listener the listener to add.
  1210.      * @see #removeBevelStyleListener
  1211.      */
  1212.     public synchronized void addBevelStyleListener(VetoableChangeListener listener)
  1213.     {
  1214.         vetos.addVetoableChangeListener("bevelStyle", listener);
  1215.     }
  1216.  
  1217.     /**
  1218.      * Removes a vetoable listener for BevelStyle changes.
  1219.      * @param listener the listener to remove.
  1220.      * @see #addBevelStyleListener
  1221.      */
  1222.     public synchronized void removeBevelStyleListener(VetoableChangeListener listener)
  1223.     {
  1224.         vetos.removeVetoableChangeListener("bevelStyle", listener);
  1225.     }
  1226.  
  1227.     /**
  1228.      * This is the PropertyChangeEvent handling inner class for the constrained BevelStyle property.
  1229.      * Handles vetoing BevelStyles that are not valid.
  1230.      */
  1231.     class Veto implements java.beans.VetoableChangeListener, java.io.Serializable
  1232.     {
  1233.         /**
  1234.          * This method gets called when an attempt to change the constrained BevelStyle property is made.
  1235.          * Ensures the given Orientation is valid.
  1236.          *
  1237.          * @param     e a <code>PropertyChangeEvent</code> object describing the
  1238.          *             event source and the property that has changed.
  1239.          * @exception PropertyVetoException if the recipient wishes the property
  1240.          *              change to be rolled back.
  1241.          */
  1242.         public void vetoableChange(PropertyChangeEvent e) throws PropertyVetoException
  1243.         {
  1244.             int i = ((Integer)e.getNewValue()).intValue();
  1245.             if (!isValidBevelStyle(i))
  1246.             {
  1247.                 throw new PropertyVetoException(errors.getString("InvalidBevelStyle") + i, e);
  1248.             }
  1249.         }
  1250.     }
  1251.  
  1252.     /**
  1253.      * Sizes the border panel from the padding, inset, and label margin information.
  1254.      * @param force force setBounds even if the overall size hasn't changed
  1255.      */
  1256.     protected void sizepanel(boolean force)
  1257.     {
  1258.         Dimension s;
  1259.  
  1260.         s = size();
  1261.  
  1262.         if (force || oldSize.width != s.width || oldSize.height != s.height)
  1263.         {
  1264.             oldSize = s;
  1265.             panel.setBounds(padleft + ixPad,
  1266.                   getLabelTopMargin() + iyPadTop,
  1267.                   s.width - padright - padleft - ixPad * 2 - 1,
  1268.                   s.height - padbottom - getLabelTopMargin() - iyPadBottom - iyPadTop - 1);
  1269.         }
  1270.     }
  1271.  
  1272.     /**
  1273.      * Draws the border panel.
  1274.      * @param g current graphics object
  1275.      */
  1276.     protected void draw(Graphics g)
  1277.     {
  1278.         Dimension s;
  1279.         int delta;
  1280.         FontMetrics fm;
  1281.         int x;
  1282.         int y;
  1283.         int w;
  1284.         int h;
  1285.  
  1286.         s = size();
  1287.         delta = padtop;
  1288.         fm = getFontMetrics(getFont());
  1289.  
  1290.         g.clipRect(0, 0, s.width, s.height);
  1291.         //Erase our background.
  1292.         g.fillRect(0, 0, s.width, s.height);
  1293.  
  1294.         if (label != null && fm != null)
  1295.         {
  1296.             delta = (fm.getAscent()  + fm.getDescent() + padtop) / 2;
  1297.         }
  1298.  
  1299.         x = padleft;
  1300.         y = delta;
  1301.         w = s.width - padleft - padright - 1;
  1302.         h = s.height - 1 - delta - padbottom;
  1303.  
  1304.         drawBorder(g, x, y, w, h);
  1305.  
  1306.         drawLabel(g, fm);
  1307.     }
  1308.  
  1309.     /**
  1310.      * Draws the border panel border.
  1311.      * @param g current graphics object
  1312.      * @param x x coordinate of panel object
  1313.      * @param y y coordinate of panel object
  1314.      * @param w w width of panel object
  1315.      * @param h h height of panel object
  1316.      */
  1317.     protected void drawBorder(Graphics g, int x, int y, int w, int h)
  1318.     {
  1319.         switch(style)
  1320.         {
  1321.             case BEVEL_RAISED :
  1322.             {
  1323.                 g.setColor(bevelLighterColor);
  1324.                 g.drawLine(x, y, x + w, y);
  1325.                 g.drawLine(x, y, x, y + h);
  1326.                 g.setColor(bevelDarkerColor);
  1327.                 g.drawLine(x, y + h, x + w, y + h);
  1328.                 g.drawLine(x + w, y, x + w, y + h);
  1329.                 break;
  1330.             }
  1331.             case BEVEL_LOWERED :
  1332.             {
  1333.                 g.setColor(bevelDarkerColor);
  1334.                 g.drawLine(x, y, x + w, y);
  1335.                 g.drawLine(x, y, x, y + h);
  1336.                 g.setColor(bevelLighterColor);
  1337.                 g.drawLine(x, y + h, x + w, y + h);
  1338.                 g.drawLine(x + w, y, x + w, y + h);
  1339.                 break;
  1340.             }
  1341.             case BEVEL_NONE :
  1342.             {
  1343.                 break;
  1344.             }
  1345.             case BEVEL_LINE :
  1346.             {
  1347.                 g.setColor(borderColor);
  1348.                 g.drawRect(x, y, w, h);
  1349.                 break;
  1350.             }
  1351.             default:
  1352.             {
  1353.                 g.setColor(borderColor);
  1354.                 g.drawRect(x, y, w, h);
  1355.                 break;
  1356.             }
  1357.         }
  1358.     }
  1359.  
  1360.     /**
  1361.      * Draws the border panel label.
  1362.      * @param g current graphics object
  1363.      * @param fm FontMetrics of border panel label
  1364.      */
  1365.     protected void drawLabel(Graphics g, FontMetrics fm)
  1366.     {
  1367.         if (label != null && (fm != null))
  1368.         {
  1369.             int fWidth;
  1370.             Dimension s;
  1371.             int stringWidth;
  1372.             int ascent;
  1373.             int descent;
  1374.             int x;
  1375.             int y;
  1376.             int h;
  1377.  
  1378.             fWidth = 10;
  1379.             s = size();
  1380.  
  1381.             if (getFont().getSize() > fWidth)
  1382.             {
  1383.                 fWidth = fWidth + getFont().getSize() / 2;
  1384.             }
  1385.  
  1386.             stringWidth = fm.stringWidth(label);
  1387.             ascent      = fm.getAscent();
  1388.             descent     = fm.getDescent();
  1389.  
  1390.             switch(labelAlignment)
  1391.             {
  1392.                 case Label.CENTER:
  1393.                 {
  1394.                     x = padleft + (s.width - padleft - padright - stringWidth) / 2;
  1395.                     break;
  1396.                 }
  1397.                 case Label.RIGHT:
  1398.                 {
  1399.                     x = s.width - fWidth - (stringWidth + (labelpadx + labelipadx) / 2) - padright;
  1400.                     break;
  1401.                 }
  1402.                 case Label.LEFT:
  1403.                 {
  1404.                 }
  1405.                 default:
  1406.                 {
  1407.                     x = fWidth + (labelpadx + labelipadx) / 2 + padleft;
  1408.                 }
  1409.             }
  1410.  
  1411.             //y = ascent + padtop;            //This line is useless. 12/17/96 Levi Brown
  1412.             h = ascent + descent+padtop;
  1413.  
  1414.             y = (fWidth - h) / 2 + (padtop + ascent);
  1415.             //h = fWidth;                    //I like h better before... 12/17/96 Levi Brown
  1416.  
  1417.             g.setColor(getBackground());
  1418.             //Commented out the line below, to add my own below it.  12/17/96 Levi Brown
  1419.             //g.fillRect(x - labelipadx / 2, 0, stringWidth + labelipadx, h);
  1420.             g.fillRect(x - labelipadx / 2, y - 1 - ascent - padtop/2, stringWidth + labelipadx, h);
  1421.             g.setColor(labelColor);
  1422.             g.drawString(label, x, y - 1);
  1423.         }
  1424.     }
  1425.  
  1426.     /**
  1427.      * Returns the current margin above the label.
  1428.      */
  1429.     protected int getLabelTopMargin()
  1430.     {
  1431.         int  top;
  1432.         Font font;
  1433.  
  1434.         if (label == null)
  1435.         {
  1436.             return padtop;
  1437.         }
  1438.  
  1439.         top  = padtop;
  1440.         font = getFont();
  1441.  
  1442.         if (font != null)
  1443.         {
  1444.             FontMetrics fm;
  1445.  
  1446.             fm  = getFontMetrics(font);
  1447.             top = fm.getAscent() + fm.getDescent() + padtop + 0;
  1448.         }
  1449.  
  1450.         return top;
  1451.     }
  1452.  
  1453.     /**
  1454.      * Returns the current label width margin.
  1455.      */
  1456.     protected int getLabelWidthMargin()
  1457.     {
  1458.         if (label == null)
  1459.         {
  1460.             return 0;
  1461.         }
  1462.  
  1463.         int w;
  1464.         Font font;
  1465.  
  1466.         w = 2 + internalInsets.left + internalInsets.right;
  1467.         font = getFont();
  1468.  
  1469.         if (font != null)
  1470.         {
  1471.             FontMetrics fm;
  1472.  
  1473.             fm = getFontMetrics(font);
  1474.             w  = Math.max(w, 2 + fm.stringWidth(label) + labelpadx + labelipadx);
  1475.         }
  1476.  
  1477.         return w;
  1478.     }
  1479.  
  1480.     /**
  1481.      * Used to calculate the hilight colors from the background color.
  1482.      * @see #paint
  1483.      */
  1484.     protected void calculateHilightColors(Color c)
  1485.     {
  1486.         bevelLighterColor    = ColorUtils.calculateHilightColor(c);
  1487.         bevelDarkerColor    = ColorUtils.calculateShadowColor(c);
  1488.     }
  1489.  
  1490.     /**
  1491.      * The overall size before sizepanel().
  1492.      */
  1493.     Dimension oldSize = new Dimension();
  1494.  
  1495.     /**
  1496.      * Label horizontal coordinate padding constant, in pixels.
  1497.      */
  1498.     protected static final int labelpadx = 10;
  1499.     /**
  1500.      * Label horizontal coordinate inset constant, in pixels.
  1501.      */
  1502.     protected static final int labelipadx = 4;
  1503.  
  1504.     /**
  1505.      * Cached value of the background color.  Used to determine if calculated colors need to be updated.
  1506.      */
  1507.     protected Color cachedBackground    = null;
  1508.     /**
  1509.      * The border color.
  1510.      */
  1511.     protected Color borderColor;
  1512.     /**
  1513.      * The color to use as a hilight when BevelStyle is BEVEL_RAISED or BEVEL_LOWERED.
  1514.      */
  1515.     protected Color bevelLighterColor;
  1516.     /**
  1517.      * The color to use as a hilight when BevelStyle is BEVEL_RAISED or BEVEL_LOWERED.
  1518.      */
  1519.     protected Color bevelDarkerColor;
  1520.     /**
  1521.      * The border label color.
  1522.      */
  1523.     protected Color labelColor;
  1524.     /**
  1525.      * The top border outside padding amount, in pixels.
  1526.      * This is the distance between the drawn border and the actual
  1527.      * bounds of the component.
  1528.      */
  1529.     protected int padtop;
  1530.     /**
  1531.      * The bottom border outside padding amount, in pixels.
  1532.      * This is the distance between the drawn border and the actual
  1533.      * bounds of the component.
  1534.      */
  1535.     protected int padbottom;
  1536.     /**
  1537.      * The left border outside padding amount, in pixels.
  1538.      * This is the distance between the drawn border and the actual
  1539.      * bounds of the component.
  1540.      */
  1541.     protected int padleft;
  1542.     /**
  1543.      * The right border outside padding amount, in pixels.
  1544.      * This is the distance between the drawn border and the actual
  1545.      * bounds of the component.
  1546.      */
  1547.     protected int padright;
  1548.     /**
  1549.      * The side border inset padding amount, in pixels.
  1550.      * This is the distance between the drawn border and the usable
  1551.      * area within the border. It is used to determine the size of the
  1552.      * panel contained within this component's borders.
  1553.      * @see #panel
  1554.      */
  1555.     protected int ixPad;
  1556.     /**
  1557.      * The top border inset padding amount, in pixels.
  1558.      * This is the distance between the drawn border and the usable
  1559.      * area within the border. It is used to determine the size of the
  1560.      * panel contained within this component's borders.
  1561.      * @see #panel
  1562.      */
  1563.     protected int iyPadTop;
  1564.     /**
  1565.      * The bottom border inset padding amount, in pixels.
  1566.      * This is the distance between the drawn border and the usable
  1567.      * area within the border. It is used to determine the size of the
  1568.      * panel contained within this component's borders.
  1569.      * @see #panel
  1570.      */
  1571.     protected int iyPadBottom;
  1572.     /**
  1573.      * The border style: BEVEL_RAISED, BEVEL_LOWERED, BEVEL_LINE, or BEVEL_NONE.
  1574.      * @see BevelStyle#BEVEL_RAISED
  1575.      * @see BevelStyle#BEVEL_LOWERED
  1576.      * @see BevelStyle#BEVEL_LINE
  1577.      * @see BevelStyle#BEVEL_NONE
  1578.      */
  1579.     protected int style;
  1580.     /**
  1581.      * The text label to display in the border.
  1582.      */
  1583.     protected String label;
  1584.     /**
  1585.      * The border label alignment: ALIGN_LEFT, ALIGN_CENTERED, or ALIGN_RIGHT.
  1586.      * @see AlignStyle#ALIGN_LEFT
  1587.      * @see AlignStyle#ALIGN_CENTERED
  1588.      * @see AlignStyle#ALIGN_RIGHT
  1589.      */
  1590.     protected int labelAlignment;
  1591.     /**
  1592.      * The internal border insets.
  1593.      * The left and right fields are used while determining the preferred
  1594.      * width of this component.
  1595.      */
  1596.     protected Insets internalInsets;
  1597.     /**
  1598.      * The panel within the border. This is the panel that contains the
  1599.      * components added to the BorderPanel.
  1600.      */
  1601.     protected Panel panel;
  1602.     /**
  1603.      * Error strings.
  1604.      */
  1605.     transient protected ResourceBundle errors;
  1606.  
  1607.     private Vector cListeners = null;
  1608.     private Veto veto = null;
  1609.     private symantec.itools.beans.VetoableChangeSupport vetos = new symantec.itools.beans.VetoableChangeSupport(this);
  1610.     private symantec.itools.beans.PropertyChangeSupport changes = new symantec.itools.beans.PropertyChangeSupport(this);
  1611. }
  1612.